


clear all 
use the_dataset.dta

keep if  standard == 1

* Create globals to estimate
global covariates1 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1
global covariates2 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17 
global covariates3 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17 yeardummy1-yeardummy9

* This generates the trimmed samples for main estimations

* Generate Trimmed samples
preserve
keep if case_1==1
teffects nnmatch (culture_d $covariates1) (unemp), ematch(CCAA1 ANOENC1) nneighbor(3) atet biasadj($covariates1) gen (var)

keep var1 var2 var3 var4 unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen culture_1 =1
save "trimmedt01.dta", replace
restore

preserve
keep if case_2==1
teffects nnmatch (culture_d $covariates2) (unemp), ematch(ANOENC1) nneighbor(3) atet biasadj($covariates2) gen (var)
keep var1 var2 var3  unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen culture_2 =1
save "trimmedt12.dta", replace
restore
********************************************************************************

* This generates the trimmed samples for COP estimations

clear all 
use the_dataset.dta

keep if  standard == 1

global covariates1 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1
global covariates2 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17 
global covariates3 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17 yeardummy1-yeardummy9

* 1.0 Gen participation
gen c_c1 = 1 if culture1 > 0
gen c_c2 = 1 if culture2 > 0
replace c_c2 = 0 if culture2 == 0

* 1.1 Gen trimmed COP T01
* Participation
preserve
keep if case_1 == 1
teffects nnmatch (c_c2 $covariates1) (unemp), ematch(ANOENC1 CCAA1) nneighbor(3) atet biasadj($covariates1) gen (var)
keep var1 var2 var3 unemp case_1
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen part_culture_1 =1
save "part_cop_t01.dta", replace
restore

* Expenditure
preserve
keep if case_1 == 1  & c_c2 == 1
teffects nnmatch (culture_d $covariates2) (unemp), ematch(ANOENC1) nneighbor(3) atet biasadj($covariates2) gen (var)

keep var1 var2 var3  unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen mes_culture_1 =1
save "exp_cop_t01.dta", replace
restore


* 1.2 Gen trimmed COP T12
*Participation
preserve
keep if case_2==1
teffects nnmatch (c_c2 $covariates2) (unemp), ematch(ANOENC1) nneighbor(3) atet biasadj($covariates2) gen (var)

keep var1 var2 var3  unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen part_culture_2 =1
save "part_cop_t12.dta", replace
restore
* Expenditure
preserve
keep if case_2==1 & c_c2 == 1
teffects nnmatch (culture_d $covariates2) (unemp), ematch(ANOENC1) nneighbor(3) atet biasadj($covariates2) gen (var)

keep var1 var2 var3  unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen mes_culture_2 =1
save "exp_cop_t12.dta", replace
restore
********************************************************************************


clear all 
use the_dataset.dta
keep if  standard == 1

global covariates culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17

* books1 books2 for books performance1 performance2 museums1 museums2
local out1 books1
local out2 books2

gen outcome1 = `out1'
gen outcome2 = `out2'
gen outcome_d = outcome2 - outcome1

* 1.1 Generate participation
gen m_m1 = 1 if outcome1 > 0
gen m_m2 = 1 if outcome2 > 0
replace m_m2 = 0 if outcome2 == 0

* 1.2 Gen trimmed sample T01 for participation
preserve
teffects nnmatch (m_m2 $covariates) (unemp) if case_1==1,   ematch(ANOENC1) nneighbor(3) atet biasadj($covariates) gen (var)

keep var1 var2 var3 var4 unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen outcome_1 =1
save "p_outcome_t01.dta", replace
restore

* 1.3 Gen trimmed sample T12 for participation
preserve
teffects nnmatch (m_m2 $covariates) (unemp) if case_2==1, ematch(ANOENC1) nneighbor(3) atet biasadj($covariates) gen (var)

keep var1 var2 var3 unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen outcome_2 =1
save "p_outcome_t12.dta", replace
restore

* 1.2 Gen trimmed sample T01 for outcome
preserve
keep if case_1==1 & m_m2 == 1
teffects nnmatch (m_m2 $covariates) (unemp),  ematch(ANOENC1) nneighbor(3) atet biasadj($covariates) gen (var)

keep var1 var2 var3 unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen outcome_1 =1
save "m_outcome_t01.dta", replace
restore

* 1.3 Gen trimmed sample T12 for outcome
preserve
keep if case_2==1 & m_m2 == 1
teffects nnmatch (m_m2 $covariates) (unemp), ematch(ANOENC1) nneighbor(3) atet biasadj($covariates) gen (var)

keep var1 var2 var3 unemp
keep if unemp==1
gen ind=_n
reshape long var, i(ind) j(match)
sort var
quietly by var:  gen dup = cond(_N==1,0,_n)
keep if dup==0 | dup==1
keep var
gen outcome_2 =1
save "m_outcome_t12.dta", replace
restore



